package cn.echo.ecc.web.controller;

import cn.echo.ecc.dto.AlipayNotifyDto;
import cn.echo.ecc.dto.PayApplyDto;
import cn.echo.ecc.dto.PayExtParamDto;
import cn.echo.ecc.result.JSONResult;
import cn.echo.ecc.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    /**
     * 根据订单编号轮询查询支付单是否存在
     * @param orderNo
     * @return
     */
    @RequestMapping(value = "/checkPayOrder/{orderNo}",method = RequestMethod.GET)
    public JSONResult checkPayOrder(@PathVariable("orderNo")String orderNo){
        return payService.checkPayOrder(orderNo);
    }

    /**
     * 发起支付
     * @param payApplyDto
     * @return
     */
    @RequestMapping(value="/apply",method= RequestMethod.POST)
    public JSONResult apply(@RequestBody @Valid PayApplyDto payApplyDto){
        return JSONResult.success(payService.apply(payApplyDto));
    }

    /**
     * 支付宝异步回调业务处理
     * @param alipayNotifyDto
     * @return
     */
    @RequestMapping(value="/alipay/notify",method= RequestMethod.POST)
    public String notify(AlipayNotifyDto alipayNotifyDto){
        return payService.notify(alipayNotifyDto);
    }
}
